<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习</title>
</head>

<body>
    <script>

        // 练习5
        // 输入一个数字，给这段数字添加千位符
        // 比如 输入12345 输出12,345

        let a = prompt('请输入一个数字：')
        console.log(a);
        let b = a.length    // 备份字符串的长度
        for (let i = b - 3; i > 0; i -= 3) {
            // 在插入逗号的位置，将原始数组先拆分成两份
            let first = a.substring(0, i)
            let last = a.substring(i)
            a = first + ',' + last
        }
        console.log(a);





    </script>
</body>

</html>